import $toast from './toast'
const Index = {
    // 返回刷新
    back_refresh(method,data){
        method = method || 'back_refresh'
        const page = getCurrentPages()
        const before = page[page.length-2]
        before?.[method]?.()
        if( data ){
            before.setData(data)
        }
        wx.navigateBack()
    },
    // h5
    h5(opt){
        let { url, title } = opt || {}
        if( url ){
            url = '?url=' + decodeURIComponent(url);
            title = title ? '&title=' + title : ''
            wx.navigateTo({ 
                url:'/pages/h5/index' + url + title
            })
        }else{
            $toast.info('url 不存在')
        }
    },
    call(phone){
        wx.makePhoneCall({
            phoneNumber:phone,
            fail(){
                $toast.info('拨打电话失败！')
            }
        })
    }
}
export default Index